package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("条件分页查询护项目")
    public ResponseResult<PageResponse<NursingProjectVo>> list(@ApiParam(value = "护理项目名称", required = false) String name,
                                                               @ApiParam(value = "当前页码", defaultValue = "1") Integer pageNum,
                                                               @ApiParam(value = "当前页码", defaultValue = "10") Integer pageSize,
                                                               @ApiParam(value = "状态", required = false) Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.list(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    private ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id查询护理项目")
    private ResponseResult<NursingProjectVo> findById(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        NursingProjectVo nursingProjectVo=nursingProjectService.findById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        nursingProjectService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("禁用或启用护理项目")
    public ResponseResult enableOrDisable(@PathVariable @ApiParam(value = "ID", required = true) Long id,
                                          @PathVariable @ApiParam(value = "状态", required = true) Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }


    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> all(){
        List<NursingProjectVo> nursingProjectVOList = nursingProjectService.all();
        return success(nursingProjectVOList);
    }
}
